package com.lefevre.cms.web.action.common;

import com.lefevre.cms.service.theme.ThemeService;
import com.lefevre.cms.web.action.AccessDeviceUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * favicon.ico图标
 */
@Controller
public class FaviconAction {

    @Resource
    AccessDeviceUtil accessDeviceUtil;
    @Resource(name = "themeServiceImpl")
    private ThemeService themeService;

    @RequestMapping(value = {"/favicon.ico", "/apple-touch-icon.png", "/apple-touch-icon-120x120.png"})
    public String favicon(HttpServletRequest request, HttpServletResponse response
    ) throws Exception {

        //当前模板使用的目录
        String dirName = themeService.findTemplateDir_cache();

        return "forward:/common/" + dirName + "/" + accessDeviceUtil.accessDevices(request) + "/images/favicon.ico";
    }
}
